package com.qiaofang.collectmanage.service.impl;

import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.collectmanage.service.CrawlerSubTaskService;
import com.qiaofang.collectmanage.dao.CrawlerSubTaskDao;
import com.qiaofang.collectmanage.dao.domain.CrawlerSubTask;
import com.qiaofang.collectmanage.service.util.CrawlerSubTaskConvert;
import com.qiaofang.collectmanage.stub.bean.CrawlerSubTaskDTO;
import com.qiaofang.collectmanage.stub.bean.SearchCrawlerSubTaskDTO;
import com.qiaofang.collectmanage.stub.bean.SaveCrawlerSubTaskDTO;
import com.qiaofang.collectmanage.stub.bean.UpdateCrawlerSubTaskDTO;
import com.qiaofang.collectmanage.stub.bean.ListCrawlerSubTaskDTO;

/**
* Created by generator on 2018-8-1 14:39:02
*/
@Service("subTaskService")
public class CrawlerSubTaskServiceImpl implements CrawlerSubTaskService {

    @Autowired
    private CrawlerSubTaskDao subTaskDao;


    @Override
    public CrawlerSubTaskDTO getCrawlerSubTaskByUuid(String uuid){
        CrawlerSubTask domain = subTaskDao.getCrawlerSubTaskByUuid(uuid);
        return   CrawlerSubTaskConvert.convertDomain2DTO(domain);
    }
    @Override
    public CrawlerSubTaskDTO getCrawlerSubTaskBySubTask(CrawlerSubTaskDTO dto){
          CrawlerSubTask domain = subTaskDao.getCrawlerSubTaskByCrawlerSubTask(CrawlerSubTaskConvert.convertDTO2Domain(dto));
          return CrawlerSubTaskConvert.convertDomain2DTO(domain);
    }

    @Override
    public int saveCrawlerSubTask(SaveCrawlerSubTaskDTO dto) {
         return subTaskDao.saveCrawlerSubTask (CrawlerSubTaskConvert.convertSaveDTO2Domain(dto));
    }

    @Override
    public int updateCrawlerSubTask (UpdateCrawlerSubTaskDTO dto) {
         return subTaskDao.updateCrawlerSubTask( CrawlerSubTaskConvert.convertUpdateDTO2Domain(dto));
    }


    @Override
    public int removeCrawlerSubTaskByUuid (String uuid) {
      return subTaskDao.removeCrawlerSubTaskByUuid(uuid);
    }
    @Override
    public List<CrawlerSubTaskDTO> listCrawlerSubTask(ListCrawlerSubTaskDTO dto){
          return  subTaskDao.listCrawlerSubTask(CrawlerSubTaskConvert.convertListDTO2Domain(dto)).stream().map(CrawlerSubTaskConvert::convertDomain2DTO).collect(Collectors.toList());
    }


    @Override
    public List<CrawlerSubTaskDTO> listCrawlerSubTaskByUuids(List<String> uuidList){
         return  subTaskDao.listCrawlerSubTaskByUuids(uuidList).stream().map(CrawlerSubTaskConvert::convertDomain2DTO).collect(Collectors.toList());
    }
    @Override
    public Long countCrawlerSubTask(CrawlerSubTaskDTO dto){
        return  subTaskDao.countCrawlerSubTask(CrawlerSubTaskConvert.convertDTO2Domain(dto));
    }
    @Override
    public List<CrawlerSubTaskDTO> searchCrawlerSubTaskByPermission(SearchCrawlerSubTaskDTO dto, PageDTO page){
        List<CrawlerSubTask> list = subTaskDao.searchCrawlerSubTaskByPermission(dto,page);
        return list!=null?list.stream().map(CrawlerSubTaskConvert::convertDomain2DTO).collect(Collectors.toList()):null;
    }
    @Override
    public Long countCrawlerSubTaskByPermission(SearchCrawlerSubTaskDTO dto){
           return subTaskDao.countCrawlerSubTaskByPermission(dto);
    }
}
